import React from 'react'


export default class From extends React.Component{
    constructor(...arg){
        super(...arg)
        this.state={
            username:'',
            content:''
        }
    }
    render(){
        const {username,content} = this.state
        return(<div className='from'>
            <p className='f_item'><span className='f_tit'>用户名：</span>
                <input type="text" className='f_input' value={username} onChange={this.handleNameChange.bind(this)}/>
            </p>
            <p className='f_item'><span className='f_tit'>发表评论：</span>
                <input type="text" className='f_input' value={content} onChange={this.handleContentChange.bind(this)}/>
            </p>
            <p><button onClick={this.handlerSubmit.bind(this)}>提交</button></p>
        </div>)
    }


    handlerSubmit(){
     const comment = this.state;
     this.props.addcomments(comment)
    }


    handleNameChange(e){
        let username = e.target.value;

        this.setState({
            username:username
        })
    }

    handleContentChange(e){
        let content = e.target.value;
        this.setState({
            content:content
        })
    }
}